﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_PET_IMAGE
	/// </summary>
	public partial class DAL_T_PET_IMAGE
	{
		public DAL_T_PET_IMAGE()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string PET_IMAGE_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_PET_IMAGE");
			strSql.Append(" where PET_IMAGE_ID=:PET_IMAGE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_IMAGE_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_IMAGE_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_PET_IMAGE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PET_IMAGE(");
			strSql.Append("PET_IMAGE_ID,NAME,PATH,REG_ORG_ID,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,ATTACHMENT_TYPE)");
			strSql.Append(" values (");
			strSql.Append(":PET_IMAGE_ID,:NAME,:PATH,:REG_ORG_ID,:CREATE_TIME,:CREATOR_ID,:UPDATE_TIME,:UPDATOR_ID,:ATTACHMENT_TYPE)");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_IMAGE_ID", OracleType.VarChar,40),
					new OracleParameter(":NAME", OracleType.NVarChar),
					new OracleParameter(":PATH", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":ATTACHMENT_TYPE", OracleType.Number,10)};
			parameters[0].Value = model.PET_IMAGE_ID;
			parameters[1].Value = model.NAME;
			parameters[2].Value = model.PATH;
			parameters[3].Value = model.REG_ORG_ID;
			parameters[4].Value = model.CREATE_TIME;
			parameters[5].Value = model.CREATOR_ID;
			parameters[6].Value = model.UPDATE_TIME;
			parameters[7].Value = model.UPDATOR_ID;
			parameters[8].Value = model.ATTACHMENT_TYPE;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_PET_IMAGE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PET_IMAGE set ");
			strSql.Append("NAME=:NAME,");
			strSql.Append("PATH=:PATH,");
			strSql.Append("REG_ORG_ID=:REG_ORG_ID,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID,");
			strSql.Append("ATTACHMENT_TYPE=:ATTACHMENT_TYPE");
			strSql.Append(" where PET_IMAGE_ID=:PET_IMAGE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":NAME", OracleType.NVarChar),
					new OracleParameter(":PATH", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":ATTACHMENT_TYPE", OracleType.Number,10),
					new OracleParameter(":PET_IMAGE_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.NAME;
			parameters[1].Value = model.PATH;
			parameters[2].Value = model.REG_ORG_ID;
			parameters[3].Value = model.CREATE_TIME;
			parameters[4].Value = model.CREATOR_ID;
			parameters[5].Value = model.UPDATE_TIME;
			parameters[6].Value = model.UPDATOR_ID;
			parameters[7].Value = model.ATTACHMENT_TYPE;
			parameters[8].Value = model.PET_IMAGE_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string PET_IMAGE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_IMAGE ");
			strSql.Append(" where PET_IMAGE_ID=:PET_IMAGE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_IMAGE_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_IMAGE_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PET_IMAGE_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_IMAGE ");
			strSql.Append(" where PET_IMAGE_ID in ("+PET_IMAGE_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_PET_IMAGE GetModel(string PET_IMAGE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_IMAGE_ID,NAME,PATH,REG_ORG_ID,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,ATTACHMENT_TYPE from T_PET_IMAGE ");
			strSql.Append(" where PET_IMAGE_ID=:PET_IMAGE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_IMAGE_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_IMAGE_ID;

			ChinaSoft.Model.Model_T_PET_IMAGE model=new ChinaSoft.Model.Model_T_PET_IMAGE();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["PET_IMAGE_ID"]!=null && ds.Tables[0].Rows[0]["PET_IMAGE_ID"].ToString()!="")
				{
					model.PET_IMAGE_ID=ds.Tables[0].Rows[0]["PET_IMAGE_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NAME"]!=null && ds.Tables[0].Rows[0]["NAME"].ToString()!="")
				{
					model.NAME=ds.Tables[0].Rows[0]["NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PATH"]!=null && ds.Tables[0].Rows[0]["PATH"].ToString()!="")
				{
					model.PATH=ds.Tables[0].Rows[0]["PATH"].ToString();
				}
				if(ds.Tables[0].Rows[0]["REG_ORG_ID"]!=null && ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString()!="")
				{
					model.REG_ORG_ID=ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ATTACHMENT_TYPE"]!=null && ds.Tables[0].Rows[0]["ATTACHMENT_TYPE"].ToString()!="")
				{
					model.ATTACHMENT_TYPE=decimal.Parse(ds.Tables[0].Rows[0]["ATTACHMENT_TYPE"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_IMAGE_ID,NAME,PATH,REG_ORG_ID,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID,ATTACHMENT_TYPE ");
			strSql.Append(" FROM T_PET_IMAGE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PET_IMAGE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PET_IMAGE_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PET_IMAGE T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_PET_IMAGE";
			parameters[1].Value = "PET_IMAGE_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

